<?php

use Entities\Estoque;

$strBusca = $_REQUEST['strBusca'];
$responsavel = $_REQUEST['responsavel'];

$dql = "select c, sum(c.quantidade) from Entities\Estoque c JOIN c.obra o JOIN c.material m where o.id = :parametro group by m.id, c.propriedade ";

$q = $em->createQuery($dql);
$q->setParameter("parametro", $strBusca);
$materiais = $q->getResult();
$xml = "";
foreach ($materiais as $material){
	$m = $material[0];
	$qtd = $material[1];
	$xml .= "<material>";
	$xml .= "<id>".$m->getId()."</id>";
	$xml .= "<idMaterial>".$m->getMaterial()->getId()."</idMaterial>";
	$xml .= "<obra>".$strBusca."</obra>";
	$xml .= "<responsavel>".$responsavel."</responsavel>";
	$xml .= "<descricaoMaterial>".$m->getMaterial()->getDescricao()."</descricaoMaterial>";
	$xml .= "<tamanho>".$m->getPropriedade()."</tamanho>";
	$xml .= "<quantidade>".$qtd."</quantidade>";
	$xml .= "</material>";
}

echo $xml;